<?php
header('Content-type:text/html;charset=utf8');
/**
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-3-1
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet"  href="<?php echo backweb_CSS_URL;?>show.css" />
<script type="text/javascript" src="<?php echo backweb_JS_URL;?>jquery.js"></script>
<script>
function initPro() {
	 var option1 = '';
		 $.ajax({
			url:'./index.php?r=backweb/goods/search',
			type:'post',
			dataType:'json',
			success:function (jsonData){
				$.each(jsonData, function(index, indexItems) { 
					   option1 += "<option value="+indexItems.category_id+">"
					     + indexItems.name + "</option>";
					  });
				  	$("#cat").append(option1);
				  	$("#cat").bind("change", function() {
				   		selectCity(jsonData);
				  	})
			},     
			error:function (){
				alert("加载失败");
			}
	 });
	  
	 function selectCity(data) {
	  var option2 = '';

	  var selectedIndex = $("#cat :selected").text();
	  $("#bra").empty();
	  if($("#cat :selected").val() == -1){
	   $("#bra").append("<option value='1' id=\"-1\">请选择品牌</option>");
	  }
		option2 +="<option value=\"-1\">所有品牌</option>";
	  $.each(data, function(index, indexItems) {
	   var proName = indexItems.name;
	   $.each(indexItems.items, function(index, indexItems) {
	    if (indexItems.parentNode != selectedIndex) {
	     return;
	    } else {
	     option2 += "<option  value=" + indexItems.brand_id + ">"
	       + indexItems.name + "</option>";
	    }
	   })
	  });
	  $("#bra").append(option2);
	 };
	};
	$(function() {
	 initPro();
	});
	/*
		function initCat(){
			var option1 = '';
				$.ajax({
					url:'./index.php?r=backweb/goods/search',
					dataType:'json',
					success:function (jsonData){
						$.each(jsonData,function (index,items){
							option1 += "<option value="+items.category_id+">"+items.category_name+"</option>";
						}); 
						$("#cat").append(option1);
						$("#cat").bind("change",function (){
							selectBra(jsonData);
						})
					},
					error:function (){
							alert("数据加载失败");
					}
				});
			function selectBra(data){
				var option2 = '';
				var selectedIndex = $("#cat :selected").val();
				$("#bra").empty();
				if($("#cat :selected").val() == -1){
					$("#bra").append("<option id=\"-1\">请选择1</option>");
				}
				$.each(data,function(index,items){
					var catName = items.category_name;
					$.each(items.items,function(index,items){

						$.each(items.items.items,function(index,items){
							alert(items);
							
						if(items.category_id != selectedIndex){
							return;
						}else{
							option2+= "<option id="+items.brand_id+">"+items.brand_name+"</option>";
	
						}
					})
					})
				});
				$("#bra").append(option2);
			};
		};
		$(function (){
			initCat();
		})
	*/

</script>
</head>
<body>
	<input type="button"  id="button" value="点击" />
	<div id="content">
		<div id="location">当前位置：后台首页>>商品管理>><span>商品品牌</span><em><a href="./index.php?r=backweb/goods/addbrand">添加新品牌</a></em></div>
		<div id="search">
		<form action="./index.php?r=backweb/goods/brand" method="post" name="fm" id="fm">
			<select name="cat" class="text cat"  id="cat">
				<option value="-1">所有分类</option>
			</select>
			<select name="brand" class="text"  id="bra">
				<option value="-1">所有品牌</option>
			</select>
			<select name="active" class="text">
				<option value="3">全部</option>
				<option value="1">可用</option>
				<option value="0">不可用</option>
			</select>
			<span>关键字：<input type="text"   class="text" name="keyword" /><input type="submit"  class="text submit"  name="search"  value="搜索" /></span>
			</form>
		</div>
		<div id="main">
			<form action="./index.php?r=backweb/goods/sort" method="post" id="f">
				<?php foreach ($infos as $v) {?>
				<input type="hidden" name="brand_id[]" value="<?php echo $v['brand_id']; ?>" id="h" />
				<?php }?>
				<table  cellspacing="0" cellpadding="0"  bgcolor="#ffa4aa" >
					<tr><th>编号</th><th>品牌名</th><th>品牌网站</th><th>品牌介绍</th><th>所属分类</th><th>操作</th><th>是否可用</th><th><input type="submit" name="send" value="排序" style="width:50px;height:25px;"  id="submit"  /></th></tr>
					<?php foreach ($infos as $v) {?>
					<tr><td><?php echo $v['brand_id']; ?></td><td><?php echo $v['brand_name']; ?></td><td><a href="<?php echo $v['brand_url']; ?>" style="text-decoration:underline;" ><?php echo $v['brand_url']; ?></a></td><td style="width:1000px;"><?php echo $v['brand_info']; ?></td><td><a href="./index.php?r=backweb/goods/brand&category_id=<?php echo $v['category_id']; ?>"><?php echo $info[$v['category_id']]; ?></a></td><td><span><a href="./index.php?r=backweb/goods/brandupd&brand_id=<?php echo $v['brand_id']; ?>">修改</a>|<a href="#">回收站</a></span></td><td id="active" ><a href="./index.php?r=backweb/goods/active&brand_id=<?php echo $v['brand_id']; ?>&active_id=<?php echo $v['active'];?>"><?php echo $active[$v['active']]; ?></a></td><td><input type="text" name="sort[]" value="<?php echo $v['brand_sort']; ?>" style="width:40px;text-align:center;"  /></td></tr>
					<?php }?>
				</table>
			</form>
			<div id="page"><?php echo $page_list;?></div>
		</div>
		
	</div>
</body>
</html>